package org.rc.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.rc.dto.PersonPageDto;
import org.rc.entity.Personnel;
import org.rc.mapper.PersonnelMapper;
import org.rc.service.PersonnelService;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class PersonnelServiceImpl extends ServiceImpl<PersonnelMapper, Personnel> implements PersonnelService {

    @Override
    public void batchAddPersonnel(List<Personnel> personnelList) {
        this.saveBatch(personnelList);
    }

    @Override
    public void batchUpdatePersonnel(List<Personnel> personnelList) {
        this.updateBatchById(personnelList);
    }

    @Override
    public List<Personnel> getAllPersonnel() {
        return list();
    }

    @Override
    public void removeAllPersonnel() {
        this.remove(new QueryWrapper<>());
    }

    @Override
    public List<Personnel> getByName(String name) {
        QueryWrapper<Personnel> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("name",name);
        return list(queryWrapper);
    }

    @Override
    public List<Personnel> getByNames(List<String> names) {
        QueryWrapper<Personnel> queryWrapper = new QueryWrapper<>();
        queryWrapper.in("name",names);
        return list(queryWrapper);
    }

    @Override
    public Page<Personnel> getPersonPage(PersonPageDto personPageDto) {
        Page<Personnel> page = new Page<>(personPageDto.getPageNo(),personPageDto.getPageSize());
        QueryWrapper<Personnel> queryWrapper = new QueryWrapper<>();
        queryWrapper.like(StringUtils.isNotEmpty(personPageDto.getName()),"name",personPageDto.getName());
        return this.baseMapper.selectPage(page,queryWrapper);
    }
}
